from sqlalchemy import Column, Integer, String, DateTime, ForeignKey
from sqlalchemy.orm import relationship
from sqlalchemy.sql import func

from .base import Base

class Formula(Base):
    __tablename__ = "formulas"

    id = Column(Integer, primary_key=True, index=True)
    latex = Column(String, nullable=False)
    created_at = Column(DateTime(timezone=True), server_default=func.now())

    submissions = relationship("Submission", back_populates="formula")

class Submission(Base):
    __tablename__ = "submissions"

    id = Column(Integer, primary_key=True, index=True)
    formula_id = Column(Integer, ForeignKey("formulas.id"))
    image_path = Column(String, nullable=False)
    status = Column(String, default="pending")
    ocr_result = Column(String, nullable=True)
    created_at = Column(DateTime(timezone=True), server_default=func.now())

    formula = relationship("Formula", back_populates="submissions")
